package com.sdcx.agrobank.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.sdcx.agrobank.R;
import com.sdcx.agrobank.event.ChangeEvent;
import com.sdcx.agrobank.event.removeEvent;
import com.sdcx.agrobank.ui.my_activity.jiluActivity;
import com.sdcx.agrobank.util.ListDataSave;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class jiaoyiDetailActivity extends AppCompatActivity {

    private ImageView back;
    private TextView bianji,shanchu;
    private int position;
    private TextView pri;
    private ListDataSave dataSave;

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onmyEvent(removeEvent myEvent) {

    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onchEvent(ChangeEvent myEvent) {
        if (myEvent.zs==2) {
            pri.setText("+"+myEvent.price+".00");
        }else {
            pri.setText("-"+myEvent.price+".00");
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jiaoyi_detail);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        back = findViewById(R.id.back);
        bianji = findViewById(R.id.bianji);
        shanchu = findViewById(R.id.shanchu);
        pri = findViewById(R.id.price);
        EditText tim = findViewById(R.id.time);
        EditText bz = findViewById(R.id.bz);
        String time = getIntent().getStringExtra("time");
        String price = getIntent().getStringExtra("price");
        int zs = getIntent().getIntExtra("zs",0);
        position = getIntent().getIntExtra("position",0);
        tim.setText(time);
        if (zs==2) {
            pri.setText("+"+price+".00");
        }else {
            pri.setText("-"+price+".00");
        }



        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        bianji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(jiaoyiDetailActivity.this, bjActivity.class);
                intent.putExtra("position", position);
                startActivity(intent);
            }
        });
        shanchu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MingxiActivity.list.remove(position);
             //   ToastUtils.showLong(position);
                EventBus.getDefault().post(new removeEvent());
                ToastUtils.showLong("删除成功");
                dataSave = new ListDataSave(jiaoyiDetailActivity.this, "list");
                dataSave.setDataList("datas", MingxiActivity.list);
                finish();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}